/*
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License.  You may obtain a
 * copy of the License at the following location:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.baijia.commons.authentication;

import java.io.Serializable;
import java.util.List;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.baijia.commons.constant.Constant;
/**
 * @title Assertion
 * @desc Passport服务返回登录用户信息
 * @author caoliang
 * @date 2015年12月1日
 * @version 1.0
 */
public class Assertion implements Serializable {
    
    private static final long serialVersionUID = -8218650240428245287L;
    
    /** 是否新登录，当前没有使用 */
    private boolean fromNewLogin;
    /** 当前请求url和client业务系统一些属性 */
    private Service service;
    /** 第一个为登录信息。后续可能扩展proxy功能 */
    private List<Authentication> chainedAuthentications;
    
    public boolean isFromNewLogin() {
    
        return fromNewLogin;
    }


    public void setFromNewLogin(boolean fromNewLogin) {
    
        this.fromNewLogin = fromNewLogin;
    }


    public Service getService() {
    
        return service;
    }


    public void setService(Service service) {
    
        this.service = service;
    }


    public List<Authentication> getChainedAuthentications() {
    
        return chainedAuthentications;
    }


    public void setChainedAuthentications(List<Authentication> chainedAuthentications) {
    
        this.chainedAuthentications = chainedAuthentications;
    }
    
    /**
     * 获取登录用户名，一般为手机号
     * 
     * @return
     */
    public String getUsername(){
        return this.chainedAuthentications.get(0).getPrincipal().getId();
    }
    
    /**
     * 获取登录用户id
     * 
     * @param key
     * @return id
     */
    public Object getAccountId(){
        return this.chainedAuthentications.get(0).getAttributes().get(Constant.PRINCIPAL_ACCOUNTID);
    }
    
    /**
     * 获取登录用户number
     * 
     * @return number
     */
    public Object getAccountNumber(){
        return this.chainedAuthentications.get(0).getAttributes().get(Constant.PRINCIPAL_ACCOUNTNUMBER);
    }
    
    /**
     * 获取登录的机构子帐号ID
     * 
     * @return id
     */
    public Object getOrgCascadeAccountId(){
        return this.chainedAuthentications.get(0).getAttributes().get(Constant.PRINCIPAL_ORG_CASCADE_ACCOUNTID);
    }
    
    public String getAccountMobile(){
        return this.chainedAuthentications.get(0).getAttributes().get(Constant.PRINCIPAL_ACCOUNT_MOBILE).toString();
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
